package com.hualan.sfzy.controller.system;

import com.hualan.sfzy.entity.system.Role;
import com.hualan.sfzy.service.system.RoleService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName RoleController
 * @Description TODO
 * @Author Mindy
 * @Date 2025年07月09日 下午9:10
 * @Version 1.0
 */
@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/role")
    private Result add(@RequestBody Role role) {
        roleService.add(role);
        return Result.success();
    }

    @DeleteMapping("/role/{id}")
    public Result remove(@PathVariable Integer id) {
        roleService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/role")
    public Result removeBath(Integer[] ids) {
        roleService.removeBatch(ids);
        return Result.success();
    }

    @PutMapping("/role/{id}")
    public Result edit(@RequestBody Role role) {
        roleService.edit(role);
        return Result.success();
    }

    @GetMapping("/role/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(roleService.findById(id));
    }

    @GetMapping("/role/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1")Integer pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10")Integer pageSize,
                             Role role) {
        return Result.success(roleService.findByPage(pageNum, pageSize, role));
    }

    @GetMapping("/role")
    public Result find() {
        return Result.success(roleService.find());
    }
}
